package swa2012.telco.client;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;

import swa2012.telco.broker.Client;
import swa2012.telco.broker.Message;
import swa2012.telco.broker.BrokerSendMessageStatus;
import swa2012.telco.broker.Provider;
import swa2012.telco.provider.IProvider;


public class MyClient {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
//		JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
//		factory.setServiceClass(IProvider.class);
//		factory.setAddress("http://student.swa.univie.ac.at:8013/telco/Provider");
//		factory.getInInterceptors().add(new LoggingInInterceptor());
//		factory.getOutInterceptors().add(new LoggingOutInterceptor());
//		IProvider provider = (IProvider) factory.create();
//		System.out.println(provider.connectBroker());
		ClientConnector connector = new ClientConnector();
		
		Provider providerBean = new Provider();
		providerBean.setID("13");
		providerBean.setBrokerCallbackEndpoint("http://student.swa.univie.ac.at:8013/telco/BrokerCallback");
		Client clientBean = new Client();
		clientBean.setID("hansi");
		clientBean.setProvider(providerBean);
		connector.registerClient(clientBean);
//		provider.registerClient(clientBean);
//		provider.unregisterClient(clientBean);
//		Collection<Client> clientList = (Collection<Client>) provider.listClient();
//		List<Client> clientList = (List<Client>) provider.getClientList();
		List<Client> clientList = connector.getClientList();
//		client.setID("testclient");
//		client.setProvider(value)
//		provider.registerClient(client)
		for(Client c : clientList) {
//			if(c.getID().equals("herbert")) {
//				client = c;
//				System.out.println("client is set");
//			}
			System.out.println(c.getID());
		}
//		Message message = new Message();
//		message.setReceiver(client);
//		Provider provider_bean = new Provider();
//		provider_bean.setBrokerCallbackEndpoint("fake");
//		provider_bean.setID("fake");
//		Client client_fake = new Client();
//		client_fake.setID("fake");
//		client_fake.setProvider(provider_bean);
//		message.setSender(client_fake);
//		message.setText("test herbert");
//		message.setTimestamp(System.currentTimeMillis() / 1000);
//		BrokerSendMessageStatus status;
//		status = provider.sendMessage(message);
//		System.out.println(status.toString());
	}
}
